C Programming
Q41.
Consider the following C program segment: char p[20]; char *s = "string"; int length = strlen(s); int i; for (i = 0; i < length; i++) p[i] = s[length - i]; printf("%s",p); The output of the program isQ42.
In the following C program fragment, j, k, n and TwoLog_n are integer variables, and A is an array of integers. The variable n is initialized to an integer \geq 3, and TwoLog_n is initialized to the value of 2*\left \lceil log_{2}n \right \rceil for (k = 3; k < = n; k++) A[k] = 0; for (k = 2; k < = TwoLog_n; k++) for (j = k + 1; j < = n; j++) A[j] = A[j] || (j % k); for (j = 3; j < = n; j++) if (!A[j]) printf("%d", j); The set of number printed by this program fragment isQ43.
Assume the following C variable declaration int *A [10], B[10][10]; Of the following expressions I A[2] II A[2][3] III B[1] IV B[2][3] which will not give compile-time errors if used as left hand sides of assignment statements in a C program?Q44.
Consider the following C declaration: struct ( short x[5]; union { float y; long z; } u; )t; Assume that the objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment consideration, is:Q46.
The most appropriate matching for the following pairs is: \begin{array}{|ll|ll|}\hline X: & \text{m = malloc(5); m = NULL;} & 1: & \text{using dangling pointers} \\\hline Y: & \text{free(n); n -> value = 5;} & 2: & \text{using uninitialized pointers} \\\hline Z: & \text{char *p , *p = 'a' ; } & 3: & \text{lost memory} \\\hline \end{array}Q47.
The following C declarations: struct node { int i: float j; }; struct node *s[10]; define s to be:Q48.
Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number S > 0. i = 0; j = 1; while (j < n ){ if (E) j++; else if (a[j] - a[i] == S) break; else i++; } if (j < n) printf("yes") else printf ("no"); Choose the correct expression for E.Q49.
The following C function takes two ASCII strings and determines whether one is an anagram of the other. An anagram of a string s is a string obtained by permuting the letters in s. int anagram (char *a, char *b) { int count [128], j; for (j = 0; j < 128; j++) count[j] = 0; j = 0; while (a[j] && b[j]) { A; B; } for (j = 0; j < 128; j++) if (count [j]) return 0; return 1; } Choose the correct alternative for statements A and B.Q50.
Consider the following C program: #include < stdio.h > int main() { float sum = 0.0, j = 1.0, i = 2.0; while (i / j > 0.0625) { j = j + j; sum = sum + i/j; printf("%f \n", sum); } return 0; } The number of times variable sum will be printed When the above program is executed is _________ .